/*=========================================================================
 Copyright (c) 2008, Nokia Corporation and/or its subsidiary(-ies).
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
     * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
     * Neither the name of the Nokia Corporation and/or its subsidiary(-ies)nor the
       names of its contributors may be used to endorse or promote products
       derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================================*/

#ifndef ncvArithmeticOp_H
#define ncvArithmeticOp_H

#include "ncvImage.h"

/**
 * \class CArithmeticOp
 * \brief CArithmeticOp provides basic arithmetic operations for CNokiaCVImages.
 * Target and source bitmaps must be of the same size. The bitmap that is applied may be
 * smaller or larger than the two others.
 *
 * CArithmeticOp provides CNokiaCVImages with the following arithmetic and logic operations:
 *	- Add
 *	- Subtract
 *	- Multiply
 *	- Divide
 * 
 * \note Symbian TClass.
 */
class CArithmeticOp : public CImageOp
	{
	public:
		/**
		 * \enum TArithmeticOperationType
		 * \brief Specifies which arithmetic operation to do.
		 *
		 * Valid operations are:
		 * 	- EAddOperation
		 *	- ESubtractOperation
		 * 	- EMultiplyOperation
		 *	- EDivideOperation
		 *
 		 * \note Symbian TClass.
		 */
		IMPORT_C enum TArithmeticOperationType
			{
			EAddOperation = 10,
			ESubtractOperation,
			EMultiplyOperation,
			EDivideOperation
			};

		/**
		 * \brief Constructor.
		 * \param aSourceImage CNokiaCVImage to be used for source values.
		 * \param aApplyImage CNokiaCVImage to be used for values to apply to the source image
		 * \param aOperation TArithmeticOperationType operation to do
		 * \param aAbsolute Use absolute differences
		 * \param aClipColors Clip colors if they under/overflow or not.
		 * \param aOffset A constant number is added to the result of the operation
		 */
		IMPORT_C CArithmeticOp( CNokiaCVImage* aSourceImage, CNokiaCVImage* aApplyImage, 
								TArithmeticOperationType aOperation, TBool aAbsolute = EFalse, 
								TBool aClipColors = ETrue, TInt aOffset = 0);
		/**
		 * \brief Constructor.
		 * \param aSourceImage CNokiaCVImage to be used for source values.
		 * \param aValue An integer value to be applied to image with the operator.
		 * \param aOperation TArithmeticOperationType operation to do
		 * \param aAbsolute Use absolute differences
		 * \param aClipColors Clip colors if they under/overflow or not.
		 */
		IMPORT_C CArithmeticOp( CNokiaCVImage* aSourceImage, TInt aValue, TArithmeticOperationType aOperation, 
								TBool aAbsolute = EFalse, TBool aClipColors = ETrue);
		/**
		 * \brief Does the actual operation.
		 * \param aTarget CNokiaCVImage to store the result in.  Must be allocated and created beforehand.
		 * \note The function can leave. 
		 * \deprecated Use DoOperationL() instead.
		 */
		void DoOperation( CNokiaCVImage* aTarget ) { DoOperationL( aTarget ); }
		
		/**
		 * \brief Does the actual operation.
		 * \param aTarget CNokiaCVImage to store the result in.  Must be allocated and created beforehand.
		 */
		IMPORT_C void DoOperationL( CNokiaCVImage* aTarget );

	private:
		/// Private constructor.
		CArithmeticOp();

		void DoImageOperationL(CNokiaCVImage* aTarget);
		void DoIntOperationL(CNokiaCVImage* aTarget);
	private:

		/// Source image
		CNokiaCVImage*	iSource;
		/// Apply image
		CNokiaCVImage*	iApply;

		/// Operation
		TArithmeticOperationType	iOperation;

		/// Absolute values
		TBool		iAbsolute;
		/// Clip colors
		TBool		iClipColors;

		TInt		iValue;
		TInt		iOffset;
	};

#endif	// ncvArithmeticOp_H
